<template>
  <div class="header wrap">
    <h1 class="l">
      <img class="logo" src="../assets/img/indexLogo.6f8ac4f0.png" />
    </h1>
    <div class="c">
      <ul>
        <!-- :class="路径==='/user'?'active':''" -->
        <li
          @click="$router.push('/home')"
          :class="$route.path === '/home' ? 'active' : ''"
        >
          首页
        </li>
        <li
          @click="$router.push('/goods')"
          :class="$route.path === '/goods' ? 'active' : ''"
        >
          全部商品
        </li>
        <li
          @click="$router.push('/user')"
          :class="{ active: $route.path === '/user' }"
        >
          个人中心
        </li>
        <li
          @click="$router.push('/order')"
          :class="$route.path === '/order' ? 'active' : ''"
        >
          我的订单
        </li>
        <li
          @click="$router.push('/free')"
          :class="$route.path === '/free' ? 'active' : ''"
        >
          专属福利
        </li>
      </ul>
    </div>
    <div class="r">
      <input
        @keyup.enter="goToSearch"
        type="text"
        placeholder="请输入要搜索的商品"
        v-model="userInputSearch"
      />
      <span @click="goToSearch"
        ><img src="../assets/img/search.png" alt=""
      /></span>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";
export default {
  data() {
    return {
      // 绑定了用户输入框的数据v-model， 即用户输入的数据
      userInputSearch: "",
    };
  },
  methods: {
    ...mapActions({
      asyncChanIsShowToast: "toastStatus/asyncChanIsShowToast",
    }),
    goToSearch() {
      // 非空判断
      if (!this.userInputSearch.trim()) {
        this.asyncChanIsShowToast({
          msg: "请输入之后在进行搜索！",
          type: "danger",
        });
        return;
      }
      // 跳转到/goods，并且携带用户输入信息
      this.$router.push(`/goods?keyword=${this.userInputSearch}`);
      // 清空用户输入信息
      this.userInputSearch = "";
    },
  },
};
</script>
 
<style lang = "less" scoped>
@import url("../assets/css/public.less");
.header {
  height: 118px;
  /* background-color: #fcf; */
  display: flex;
  justify-content: space-between;
  align-items: center;
  .logo {
    cursor: pointer;
  }
  .c ul {
    width: 500px;
    display: flex;
    justify-content: space-between;

    li {
      cursor: pointer;
      font-size: 16px;
      font-family: SourceHanSansSC;
      font-weight: 500;

      &.active {
        color: @base-color;
        font-weight: 700;
      }
    }
  }
  .r {
    display: flex;
    input {
      width: 214px;
      height: 38px;
      border: 1px solid #dedede;
      border-radius: 20px 0px 0px 20px;
      text-indent: 1em;
    }
    span {
      width: 50px;
      height: 40px;
      background: @base-color;
      border-radius: 0px 20px 20px 0px;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
    }
  }
}
</style>